package com.bub.pay.framework.common.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * 默认用户配置
 *
 * @author recall
 * @date 2019/7/5
 */
@Slf4j
@Configuration
@AutoConfigureOrder
@ConditionalOnMissingBean(UserConfig.class)
public class DefaultUserConfig {

    @Resource
    private Environment environment;

    @PostConstruct
    public void init() {
        String[] activeProfiles = environment.getActiveProfiles();
        log.info("==================Environment[{}]====================", (Object) activeProfiles);
        ConditionSwaggerConfig.activeProfiles(activeProfiles);
    }

    @Bean
    public UserConfig defaultUserConfigBean() {
        return new UserConfig() {
            @PostConstruct
            public void init() {
                log.info("==================DefaultUserConfig====================");
                log.debug("> tokenExpire = {}", getTokenExpire());
                log.debug("> payPwdExpire = {}", getPayPwdExpire());
                log.debug("> hisTokenExpire = {}", getHisTokenExpire());
                log.debug("> googleSecretExpire = {}", getGoogleSecretExpire());
                log.debug("> payPassErrorExpire = {}", getPayPassErrorExpire());
                log.debug("> maxPayPassError = {}", getMaxPayPassError());
                log.debug("> googleErrorExpire = {}", getGoogleErrorExpire());
                log.debug("> maxGoogleError = {}", getMaxGoogleError());
                log.debug("> tokenIdentification = {}", getTokenIdentification());
                log.debug("> emailVerificationCode = {}", getEmailVerificationCodeExpire());
                log.debug("==================DefaultUserConfig====================");
            }

            @Override
            public int getTokenExpire() {
                return DEFAULT_TOKEN_EXPIRE;
            }

            @Override
            public int getPayPwdExpire() {
                return DEFAULT_MER_PAY_PWD;
            }

            @Override
            public int getHisTokenExpire() {
                return DEFAULT_HIS_TOKEN_EXPIRE;
            }

            @Override
            public int getGoogleSecretExpire() {
                return DEFAULT_GOOGLE_SECRET_EXPIRE;
            }

            @Override
            public int getPayPassErrorExpire() {
                return DEFAULT_PAY_PASS_ERROR_EXPIRE;
            }

            @Override
            public int getMaxPayPassError() {
                return DEFAULT_MAX_PAY_PASS_ERROR;
            }

            @Override
            public int getGoogleErrorExpire() {
                return DEFAULT_GOOGLE_ERROR_EXPIRE;
            }

            @Override
            public int getMaxGoogleError() {
                return DEFAULT_MAX_GOOGLE_ERROR;
            }

            @Override
            public String getTokenIdentification() {
                return DEFAULT_TOKEN_IDENTIFICATION;
            }

            @Override
            public int getEmailVerificationCodeExpire() {
                return EMAIL_VERIFICATION_CODE_EXPIRE;
            }

        };
    }


}
